package com.ruoyi.web.controller.pack;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.pack.domain.PackContainer;
import com.ruoyi.pack.domain.dto.PackMaterialSummaryDto;
import com.ruoyi.pack.service.IPackContainerService;

/**
 * 物料汇总统计Controller
 * 
 * @author ruoyi
 * @date 2024-01-01
 */
@RestController
@RequestMapping("/pack/material")
public class PackMaterialController extends BaseController
{
    @Autowired
    private IPackContainerService packContainerService;

    /**
     * 物料汇总统计查询
     */
    @PreAuthorize("@ss.hasPermi('pack:material:summary')")
    @GetMapping("/summary")
    public TableDataInfo summary(PackContainer packContainer)
    {
        startPage();
        // 设置公司权限过滤 - 只查询当前用户所属公司的器具
        // 注意：这里需要根据实际的用户-公司关联关系来设置companyId
        // packContainer.setCompanyId(getCurrentUserCompanyId());
        
        List<PackMaterialSummaryDto> list = packContainerService.selectMaterialSummary(packContainer);
        return getDataTable(list);
    }

    /**
     * 获取物料汇总详情列表
     */
    @PreAuthorize("@ss.hasPermi('pack:material:summary')")
    @GetMapping("/summary/detail")
    public TableDataInfo summaryDetail(PackContainer packContainer)
    {
        startPage();
        // 设置公司权限过滤 - 只查询当前用户所属公司的器具
        // packContainer.setCompanyId(getCurrentUserCompanyId());
        
        List<PackContainer> list = packContainerService.selectMaterialSummaryDetail(packContainer);
        return getDataTable(list);
    }

    /**
     * 导出物料汇总统计数据
     */
    @PreAuthorize("@ss.hasPermi('pack:material:summary')")
    @Log(title = "物料汇总统计", businessType = BusinessType.EXPORT)
    @PostMapping("/summary/export")
    public void exportSummary(HttpServletResponse response, PackContainer packContainer)
    {
        List<PackMaterialSummaryDto> list = packContainerService.selectMaterialSummary(packContainer);
        ExcelUtil<PackMaterialSummaryDto> util = new ExcelUtil<PackMaterialSummaryDto>(PackMaterialSummaryDto.class);
        util.exportExcel(response, list, "物料汇总统计数据");
    }
}
